package com.econage.eccm.test.bus.mapper;

import com.econage.eccm.test.base.mybatis.mapper.providerstrengthen.MybatisProviderContext;
import com.google.common.base.Strings;

/**
 * Created by wjj on 2018/1/18.
 */
public class WfTemplateSqlProvider {

    public String buildQueryListSql(MybatisProviderContext context, String wfNameSearch){
        String getWfTemplateListSQL =
                " select REQUEST_ID   as template_id_, " +
                        "        request_desc as template_name_, " +
                        "        create_date  as create_date_, " +
                        "       (select mi from user_table ut where ut.USER_ID = ers.CREATE_USER_ID ) as init_name_, " +
                        "       (select NAME from ecl_groups eg where eg.ID = ers.GROUP_ID )          as group_name_, " +
                        "       (select NAME from ecl_groups eg where eg.ID = ers.SUB_GROUP_ID )      as sub_group_name_ " +
                        " from ecl_request_sheet ers " +
                        " where container_type = 3 and FOLDER_ID = 0 ";
        if(!Strings.isNullOrEmpty(wfNameSearch)){
            getWfTemplateListSQL += " and request_desc like '%#{wfNameSearch}%' ";
            context.setAdditionalParam("wfNameSearch",wfNameSearch);
        }
        return getWfTemplateListSQL;
    }

    public String buildQueryCountSql(MybatisProviderContext context, String wfNameSearch){
        String getWfTemplateCountSQL =
                " select count(1) " +
                        " from ecl_request_sheet ers " +
                        " where container_type = 3 and FOLDER_ID = 0 ";
        if(!Strings.isNullOrEmpty(wfNameSearch)){
            getWfTemplateCountSQL += " and request_desc like '%#{wfNameSearch}%' ";
            context.setAdditionalParam("wfNameSearch",wfNameSearch);
        }
        return getWfTemplateCountSQL;
    }
}
